package com.aikon.wht.jsonComponent;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.*;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;

/**
 * Created by haitao.wang on 2016/12/14.
 */
//@JsonComponent
public class BaseJsonComponent {

    public static class Serializer extends JsonSerializer {
        @Override
        public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {

        }
    }

    public static class Deserializer extends JsonDeserializer {
        @Override
        public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
            JsonToken t = jsonParser.getCurrentToken();
            // common case first:
            if (t == JsonToken.START_OBJECT) {
                jsonParser.nextToken();
                return deserializeFromObject(jsonParser, deserializationContext);
            }
            // and then others, generally requiring use of @JsonCreator
            switch (t) {
                case VALUE_STRING:
                    return deserializeFromString(jsonParser, deserializationContext);
                case VALUE_NUMBER_INT:
                    return deserializeFromNumber(jsonParser, deserializationContext);
                case VALUE_NUMBER_FLOAT:
                    return deserializeFromDouble(jsonParser, deserializationContext);
                case VALUE_EMBEDDED_OBJECT:
                    return jsonParser.getEmbeddedObject();
                case VALUE_TRUE:
                case VALUE_FALSE:
                    return deserializeFromBoolean(jsonParser, deserializationContext);
                case START_ARRAY:
                    // these only work if there's a (delegating) creator...
                    return deserializeFromArray(jsonParser, deserializationContext);
                case FIELD_NAME:
                case END_OBJECT: // added to resolve [JACKSON-319], possible related issues
                    return deserializeFromObject(jsonParser, deserializationContext);
            }
            return deserializeFromObject(jsonParser, deserializationContext);
        }

        private Object deserializeFromArray(JsonParser jsonParser, DeserializationContext deserializationContext) {
            return null;
        }

        private Object deserializeFromBoolean(JsonParser jsonParser, DeserializationContext deserializationContext) {
            return null;
        }

        private Object deserializeFromDouble(JsonParser jsonParser, DeserializationContext deserializationContext) {
            return null;
        }

        private Object deserializeFromNumber(JsonParser jsonParser, DeserializationContext deserializationContext) {
            return null;
        }

        private Object deserializeFromString(JsonParser jsonParser, DeserializationContext deserializationContext) {
            return null;
        }

        private Object deserializeFromObject(JsonParser jsonParser, DeserializationContext deserializationContext) {
            return null;
        }
    }



}
